stage.create_grid_overlay(50, 'greenyellow')
size = .3
planet = codesters.Sprite("mars", -200, -200)
planet.set_size(.4)
planet.collision_off()
stop1 = codesters.Sprite("codester", -100, -100)
stop1.set_size(size)
stop2 = codesters.Sprite("codester", 150, -100)
stop2.set_size(size)
stop3 = codesters.Sprite("codester", 150, 100)
stop3.set_size(size)
stop4 = codesters.Sprite("codester", -150, 200)
stop4.set_size(size)
stop5 = codesters.Sprite("codester", -200, 50)
stop5.set_size(size)
stage.set_background("space")
sprite = codesters.Sprite("ufo")
sprite.set_size(0.4)
sprite.go_to(-200, -200)
sprite.pen_down()
sprite.glide_to(-100, -100)
def collision(sprite, hit_sprite):
hit_sprite.hide()
# add any other actions...
sprite.event_collision(collision)
sprite.set_speed(2)
sprite.glide_to(150, -100)
sprite.glide_to(150, 100)
sprite.glide_to(-150, 200)
sprite.glide_to(-200, 50)
sprite.glide_to(-200, -200)
sprite.turn_left(360)
t = codesters.Teacher()
sets = t.find_function('set_color')
try:
tval1 = stage.get_background()
except:
tval1 = "DNE"
try:
tval2 = sprite.get_image_name()
except:
tval2 = "DNE"
try:
tval3 = len(sets)
except:
tval3 = "DNE"
try:
tval4 = sprite.get_color()
except:
tval4 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 != "space" or tval2 != 'ufo', "Great job!")
t1.add_failure(tval2 == "DNE", "Oops! Did you delete your sprite!")
t1.add_failure(tval1 == None, "Oops! Did you delete your background?")
t1.add_failure(tval1 == 'space' and tval2 == 'ufo', "Make sure you complete Requirement #1!")
t2 = TestObjective()
t2.add_success(tval3 > 0, "Great job!")
t2.add_failure(tval3 == 0, "Did you add a Set Color command?")
t3 = TestObjective()
t3.add_success(tval4 != "green", "Great job!")
t3.add_failure(tval4 == "DNE", "Oops! Did you delete your sprite?")
t3.add_failure(tval4 == "green", "Did you change the color in your Set Color command?")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)